package com.api.shopapi.mapper;

import com.api.shopapi.entity.CheckinAssessClass;
import org.apache.ibatis.annotations.*;
import org.springframework.stereotype.Component;
import org.springframework.stereotype.Repository;

import java.util.List;

/**
 * @author maochuan
 */
@Repository
@Mapper
public interface CheckinAssessClassMapper {
    @Insert("insert into checkin_assess_class " +
            "(CheckinAssessClassCode,Name,Status,StaffCode,InstitutionCode,CalculationType) " +
            "value(#{checkinAssessClass.CheckinAssessClassCode},#{checkinAssessClass.Name}," +
            "#{checkinAssessClass.Status},#{checkinAssessClass.StaffCode},#{checkinAssessClass.InstitutionCode},#{checkinAssessClass.CalculationType})")
    int insert(@Param("checkinAssessClass") CheckinAssessClass checkinAssessClass);

    @Delete("delete from checkin_assess_class where CheckinAssessClassCode=#{checkinAssessClassCode}")
    int deleteByCheckinAssessClassCode(@Param("checkinAssessClassCode") String checkinAssessClassCode);

    @Update("update checkin_assess_class set Name = #{checkinAssessClass.Name}," +
            "Status=#{checkinAssessClass.Status}," +
            "StaffCode=#{checkinAssessClass.StaffCode},InstitutionCode=#{checkinAssessClass.InstitutionCode},CalculationType=#{checkinAssessClass.CalculationType} " +
            "where CheckinAssessClassCode=#{checkinAssessClass.CheckinAssessClassCode}")
    int updateByCheckinAssessClassCode(@Param("checkinAssessClass") CheckinAssessClass checkinAssessClass);

    @Select("<script>" +
            "select * from checkin_assess_class where InstitutionCode=#{institutionCode} " +
            "<if test ='status !=-1 '>" +
            "and Status =#{status} " +
            "</if>" +
            "</script>")
    List<CheckinAssessClass> getListByInstitutionCode(@Param("institutionCode") String institutionCode,@Param("status") int status);

    @Select("select * from checkin_assess_class where CheckinAssessClassCode=#{checkinAssessClassCode} limit 1")
    CheckinAssessClass getByCheckinAssessClassCode(@Param("checkinAssessClassCode") String checkinAssessClassCode);

    @Select("select * from checkin_assess_class where Name=#{name} and InstitutionCode=#{institutionCode} limit 1")
    CheckinAssessClass getByNameAndInstitutionCode(@Param("name") String name,@Param("institutionCode") String institutionCode);

    @Select("select * from checkin_assess_class where InstitutionCode=#{institutionCode} and Status=1")
    List<CheckinAssessClass> getList(@Param("institutionCode") String institutionCode);
}
